#ifndef GMM_MOTIONDECTION_H
#define  GMM_MOTIONDECTION_H

#include <cv.h>
#include <highgui.h>
#include <cxcore.h>
//#include <cvaux.h>
#include "bgsegm_Mog.h"
#include "LearnRate.h"

#include <math.h>
//#include "MemOperator.h"

class CGmmMotionDection
{
public:
	CGmmMotionDection(void);
	~CGmmMotionDection(void);

public:
	bool FrameProc(IplImage *pImage,IplImage *pROIMask);
	IplImage *GetBgImage();
	IplImage *GetFgImage();
	CvSeq * GetObjsRect();

private:
	void RemoveIntersectedRects( CvSeq* pObjRects );
	void MergeNearRects(CvSeq *pObjRects);
	double   GetAdaptiveThre(IplImage *pGrayImage,IplImage *pImage);
    void RemoveShadow(IplImage * pCurImage,IplImage * pBackground,IplImage * pForeground);
    CvScalar  Bgr2Hsi(CvScalar Bgr);
    void FillHole(IplImage * pImg8UC1);

private:
    CLearnRate m_learnRate;

	CvSeq* pObjRectSeq ;

	CvMemStorage*  pStorageObjs;
	CvMemStorage*  pObjRectSeqMem ;

	CvGaussBGModel*  pGBgModel;
	CvGaussBGStatModelParams GBgParams;
	CvGaussShadowStatModelParams ShadowParams;

	IplImage *pResizeImage;
	IplImage *pFgImage;
    IplImage * pFg8UC3;
	//IplImage *pBgImage;
	IplImage *pResizeROIMask;

    IplImage * pBgHSV;
    IplImage * pCurHSV;

	IplConvKernel *pConvKelErode;
	IplConvKernel *pConvKelDilate;

	float m_fRatio;
	bool bFirstFrame;
	int   iMinArea;
	int   iFrameCount;
	int   iThre;
};

#endif
